from rest_framework.generics import GenericAPIView
from rest_framework.mixins import ListModelMixin,CreateModelMixin                           #mixins 列表视图方法类
from rest_framework.mixins import RetrieveModelMixin,UpdateModelMixin,DestroyModelMixin     #mixins 详情视图方法类
from apps.drf_test_0Django原始restful.models import BookinfoModels
from apps.drf_test_6_mixins二级视图.serializer import BookModelSerializer


class BookMixinGenericAPIView(GenericAPIView,ListModelMixin,CreateModelMixin):
    """
    二级视图+mixins-列表视图
    """
    queryset = BookinfoModels.objects.all()
    serializer_class = BookModelSerializer

    def get(self,request):
        return self.list(request)

    def post(self,request):
        return self.create(request)


class BookDetailMixinGenericAPIView(GenericAPIView,RetrieveModelMixin,UpdateModelMixin,DestroyModelMixin):
    """
    二级视图+mixins-详情视图
    """
    queryset = BookinfoModels.objects.all()
    serializer_class = BookModelSerializer

    def get(self,request,pk):
        return self.retrieve(request)

    def put(self,request,pk):
        return self.update(request)

    def delete(self,request,pk):
        return self.destroy(request)





